In networking, BSD socket programming is the most basic. But when perl is getting started, the biggest headache is how to start and how to Step by step. The best prescription is Example. A complete piece of code that can run (working) is far more profound than the boring manual.
The following sections describe Socket and IO: Server/client written by Socket, which can implement the simplest but most basic ta
One, example one
#!/usr/bin/perl
print "What ' s your name?";
Chomp ($name =
Explain
01 lines are labeled Interpreter is Perl execution
02 Print to screen output with print, Perl "Display content" with print;
03chomp remove the last character, that is, remove the line feed
$name =
Note that the vari
A easy example to tell you what is "2> 1" in Perl, easyexample
You can decide if make the output shown on command screen by using 2> 1 or NUL
Testing script:
Print "without null \ n ";
System ("dir2> 1");
Print "with null \ n ";
System ("dir>NUL");
Print "end \ n ";
Result:
C: \ Rebecca \ script \ perl \ Unicode> perl
51 Leisure, read a Perl instance of the Fine Solution (4th edition) of the ebook, this is the last example of the 19th chapter. Practice practiced hand to reward yourself for learning the process of knowledge.The following source file is the file to be formatted:$catxxxexoticliquids:charlottecooper: (171) 555-2222NewOrleans Cajundelights:shelleyburke: (+) 555-4822grandmakelly ' shomestead:regina Murphy: (31
Copy Code code as follows:
#!/usr/bin/perl
#use Strict;
Open (FILE1, "c:/perl/bx/bx-users.csv");
Open (FILE2, "c:/perl/bx/bx-books.csv");
Open (FILE3, "c:/perl/bx/bx-book-ratings.csv");
Open (RESULT1, ">c:/perl/bx/bx-users.txt");
My%table;
My $record 1;
My $co
Recently, I had a program to automatically capture data from some BT websites and post it to my own forum. It worked better after a few months of trial, now the source code is published for reference by Perl enthusiasts. QQ is 2637663 and we welcome Perl enthusiasts to communicate with each other.
Consists of several programs
Readcokie. pl get the cookie of the host to be uploaded once. It is permanently sa
string separator.
Copy codeThe Code is as follows :#! /Usr/bin/perl
Use strict;
Use warnings;
Sub test {
My % comments_of_url = ();
Open FILE, "While (# Skip empty lines
Next if/^ \ s * $ /;
# Use url as key and # xxx as value for each line
# Merge all the # xxx for a url
If (/amscript_cd \("(.*?) "\) {__ Amscript_wc \('(.*?) \ S + \{/){
$ Comments_of_url {$1}. = ($2 .',');
}
}
Foreach my $ key (keys % comments_of_url ){
Chomp (my $ value = $ commen
Note: When connecting using the database specified by the SID, the database is not specified in the connection.
#!/usr/bin/perl use strict;
Use warnings;
Use DBI;
My $db _name= "geneva_admin";
My $db _passwd= "geneva_admin"; My $dbh =dbi->connect ("Dbi:oracle:", "$db _name", "$db _passwd") or Die "Can" T connect to Oracle database: $DBI:: errstr\n
";
My $sth = $dbh->prepare ("Select A,b from A_tmp where a=2") or Die "Can" T prepare SQl Prepa
The main use is to find the related files in the/proc directory.
#!/usr/bin/perl use
strict;
Use warnings;
#usage: process_grep.pl processname
exit (Main (@ARGV));
Sub Main {my
$Phash;
my $ProcessName = shift;
My $PROC _dir = "/proc";
ChDir $PROC _dir;
My @pids = Glob "[0-9]*";
For my $pid (@pids) {
open (FH, "$pid/cmdline") or die "Can ' t $pid file $!";
$Phash->{$pid} = $_ while
Copy codeThe Code is as follows :#! /Usr/bin/perl
# Use strict;
Open (FILE1, "C:/Perl/BX/BX-Users.csv ");
Open (FILE2, "C:/Perl/BX/BX-Books.csv ");
Open (FILE3, "C:/Perl/BX/BX-Book-Ratings.csv ");
Open (result1, "> C:/Perl/BX/BX-Users.txt ");My % table;My $ record1;My
Using DBI, Perl makes it easy to connect to the MySQL database:
The code is as follows:
Copy Code code as follows:
#!/bin/perl
Use DBI;
# Connect to Target DBMy $dbh = Dbi->connect ("Dbi:mysql:database=eygle;host=localhost", "username", "password", {' RaiseError ' => 1});
# Insert one rowMy $rows = $dbh->do ("INSERT into Test (ID, name) VALUES (1, ' Eygle ')");
# queryMy $sqr = $dbh->pre
Copy codeThe Code is as follows :#! /Bin/perl
Use strict;
Use warnings;
My % movies;My $ film;My % reverse_result;My $ director;My @ data;
% Movies =('The shining' => 'kubrick ','Ten Commandments '=> 'demille ','Goonies '=> 'spielberg ',);
# Output the hash value. The output result is Kubrick.Print $ movies {'the shining '};
# Simultaneously output keys and valuesForeach $ film (keys % movies){Print "$ film was directed by $ movies {$ film}. \ n ";}
Copy Code code as follows:
#!/bin/perl
Use strict;
Use warnings;
My%movies;
My $film;
My%reverse_result;
My $director;
My @data;
%movies =
(
' The Shining ' => ' Kubrick ',
' Ten Commandments ' => ' DeMille ',
' Goonies ' => ' Spielberg ',
);
#输出哈希的值, the result of the output is Kubrick
Print $movies {' The Shining '};
#同时输出键和值
foreach $film (keys%movies)
{
Print "$film is directed by $movies {$film}.\n";
}
#添加空格
p
The normal subscript operation in the Perl array must be familiar to everyone, not to be explained here.What this article is trying to say is that the majority of the subscript in the Perl array can be used to greatly facilitate the operation of the array.Note: These numbers are from 0 to $ #array的.
Child array
Copy Code code as follows:
@array = (1, 2, 3, 4, 5);
@subarray = @array [0,1]; # @suba
Environment for WinDOS, two points to note:
1, the default ActivePerl under the code is GBK, so you need to convert the string to GBK will not display garbled
2, to traverse the file directory, you need to exclude a special directory.
Complete code:
Copy Code code as follows:
#!/usr/bin/perl
Use strict;
Use warnings;
Use Encode qw/from_to/;
My $path = "e:/css design";
My $filecount = 0;
Sub Parse_env {
My $path = $_[0]; #or use my ($path) = @_;
.
Perl is a language that can accomplish tasks. From the outset, Perl was designed to simplify simple work without losing the ability to deal with difficult problems. It makes it easy to manipulate the languages of numbers, text, files and directories, computers and networks, especially programs. This language should be easy to run external programs and scan the output of these programs to get something in
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.